package com.cet;

public class lambda {


    public static void main(String[] args) {

        // 1. 主动创建实现类
        MyInterfaceImpl myInterface = new MyInterfaceImpl();

        System.out.println(myInterface.sum(1, 2));

        // 2.匿名实现
        MyInterface myInterface1 = new MyInterface() {
            @Override
            public int sum(int a, int b) {
                return a * a + b * b;
            }
        };

        System.out.println(myInterface1.sum(1, 2));

        // 3.lambda, 匿名类简写
        MyInterface myInterface2 = Integer::sum;
        System.out.println(myInterface2.sum(1, 2));
    }
}

@FunctionalInterface
interface MyInterface {

    int sum(int a, int b);
}


class MyInterfaceImpl implements MyInterface {

    @Override
    public int sum(int a, int b) {
        return a + b;
    }
}